<template>
    <div class="view">
        <android-nav-bar title="微信信息" v-on:back="back"></android-nav-bar>
        <div class="box">
<!--            <div class="card-name flex">-->
<!--                <span class="iconfont icon-xingming"></span>-->
<!--                <input type="text" placeholder="请填写你的微信昵称" v-model="cardName">-->
<!--            </div>-->
            <div class="card-name flex">
                <span class="iconfont icon-weixin"></span>
                <input type="text" placeholder="请填写你的微信号" v-model="cardNumber">
            </div>
<!--            <div class="remark">-->
<!--                注：你设置的微信号和昵称不匹配将不能提现或报销!-->
<!--            </div>-->
            <div class="save" @click="save">保存</div>
        </div>

    </div>
</template>

<script lang="ts">
    import {Component, Vue, Watch} from "vue-property-decorator";
    import Scene from "@/render/Scene";
    import Http from "@/service/Http";

    import {Getter, Action, State, Mutation} from "vuex-class";
    import {InterfaceUser} from "@/interface/InterfaceUser";
    import CommonUnit from "@/unit/CommonUnit";
    import {updateUser} from "@/store/dispatches";
    import UserEntity from "@/entity/UserEntity";
    import AndroidNavBar from "@/components/aui/AndroidNavBar.vue";

    @Component({
        components: {
            AndroidNavBar
        }
    })
    export default class MineAlipay extends Scene {
        private publicPath: string = process.env.BASE_URL;
        @State("UserStore")
        public user!: InterfaceUser;
        private cardNumber: string = "";

        private back(): void {
            this.navigateBack();
        }

        private toPage(name: string, query: any = {}): any {
            this.navigateTo({
                name: name,
                query: query
            });
        }

        private get saveParameter(): any {
            let user = new UserEntity(Object.assign(this.user, {wxpay: this.cardNumber})).getBaseInfo;
            return user;
        }

        private save(): void {
            if(String(this.cardNumber).trim()==''){
                (<any> this).$createToast({
                    time: 2500,
                    type: "warn",
                    txt: `请输入您的微信号!`
                }).show();
                return;
            }
            let toast = (<any> this).$createToast({
                time: 0,
                txt: "保存中...",
                mask: true
            }).show();
            try {
                Http.post(this.api.saveBaseInfo, {...this.saveParameter}, {token: this.user.token}).then((res) => {
                    if (res.code == 1) {
                        this.authentication();
                        toast = (<any> this).$createToast({
                            time: 2500,
                            txt: "保存成功，正在更新资料",
                            mask: true,
                            onTimeout: () => {
                                this.navigateBack();
                            }
                        }).show();
                    } else {
                        this.globalSingleResultToast(res);
                    }
                });
            } catch (e) {
                toast.hide();
                (<any> this).$createToast({
                    time: 2500,
                    type: "warn",
                    txt: `网络出错,请稍后再试!`
                }).show();
            }
        }

        private mounted(): void {
            this.cardNumber=this.user.wxpay;
        }

    }
</script>

<style scoped lang="stylus">
    .view
        position relative;
        width 100vw;
        height 100vh;
        background $theme-page-common-background-color;
        overflow: hidden;

        .box
            margin-top calc(var(--safe-area-inset-top) + 47px);
            height calc(100vh - var(--safe-area-inset-top) - 47px);

            &::before
                display table;
                content '';

            .card-name
                background-color #fff;
                height 50px;
                padding 0 15px;
                border-bottom 1px solid $theme-line-color;

                span
                    display inline-block;
                    width 50px;
                    line-height 45px;
                    font-size 24px;

                input
                    display inline-block;
                    width calc(100vw - 40px - 30px);

            .remark
                padding 15px;
                color $theme-viceColor-font;
                line-height 1.5em;

            .save
                color #fff;
                height 45px;
                line-height 45px;
                text-align center;
                border-radius 200px;
                margin 30px 30px;
                background linear-gradient(to right, rgba(254, 124, 79, .6), rgba(255, 89, 163, .6));


</style>
